package com.metersbonwe.seq;

import java.util.HashMap;
import java.util.Map;

import com.metersbonwe.seq.mapper.SequenceInfoMapper;
import com.metersbonwe.seq.mapper.SequenceMapper;
import com.metersbonwe.seq.po.SequenceInfo;

public class DefaultSequenceProvider implements SequenceProvider {

    SequenceMapper     sequenceMapper;

    SequenceInfoMapper sequenceInfoMapper;

    public SequenceInfo getConfig(String queueName) {
        SequenceInfo seq = sequenceInfoMapper.selectByPrimaryKey(queueName);
        return seq;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public Long nextSeq(String name, int size) {
        Map map = new HashMap();
        map.put("seqName", name);
        map.put("seqSize", size);
        map.put("outValue", -1l);
        sequenceMapper.nextValue(map);
        return (Long) map.get("outValue");
    }

    public SequenceMapper getSequenceMapper() {
        return sequenceMapper;
    }

    public void setSequenceMapper(SequenceMapper sequenceMapper) {
        this.sequenceMapper = sequenceMapper;
    }

    public SequenceInfoMapper getSequenceInfoMapper() {
        return sequenceInfoMapper;
    }

    public void setSequenceInfoMapper(SequenceInfoMapper sequenceInfoMapper) {
        this.sequenceInfoMapper = sequenceInfoMapper;
    }
}
